<template>
	<view class="container">
		<view class="">
			<view class="head">
				
			</view>
			<view class="title">
				<view class="line"></view>
				<view class="">
					{{type_title}}
				</view>
			</view>
			<textarea placeholder="分享新鲜事..." v-model="form.content" maxlength="-1"/>
		</view>
		<view class="" style="display: flex;">
			<view class="imgs" v-if="!form.image[0]" @click="upload()">
				<image  src="../../static/img/photo.png" mode=""></image>
			</view>
			<view v-else v-for="(item,index) in form.image" :key="index" class="imgs" @click="upload()">
					<image :src="item" mode=""></image>
			</view>
		</view>			
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					content:"",
					image:[],
					type:null,
				},
				type_title:"情感天地"
			}
		},
		
		onNavigationBarButtonTap(e) {
			this.release()	
		},
		onLoad(option){
			this.form.type = option.type
			if(option.type==2){
				this.type_title = "寻人寻物"
			}
			console.log(this.form.type)
		},
		methods: {
			release(){
				this.$utils.requert({url:'dynamic',type:'post',data:this.form}).then(res=>{
						if(res.code === 1 ){
							this.$utils.showLayer(res.message)
							uni.navigateBack({
								delta:1
							})
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			//图片上传
			upload(){
			   uni.chooseImage({
				count: 3,
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], //从相册选择
				success: res=> {
					const file = res.tempFilePaths[0]
					const  token  = uni.getStorageSync('token')
					uni.uploadFile({
						url: this.$utils.domain+'/api/api/uploadImg', //仅为示例，非真实的接口地址
						filePath: file,
						
						name: 'file',
						header:{
							'accessToken':token
						},
						formData: {	
							'type': '2'
						},
						success: (res) => {
							var res = JSON.parse(res.data)
							// console.log(res.data)
							this.form.image.push(res.data.src)
						}
					});
				},
				error : function(e){
				 // console.log(e);		
				}
			  });
			},
			
		}
	}
</script>
<style>
	page {
		width: 100%;
		background-color: #fff;
	}
</style>

<style scoped>
	.container{
		width:100%;
		padding:36rpx 24rpx;
				box-sizing: border-box;
				position: relative;
	}
     .title{
		 font-size: 28rpx;
		 color:#8A8989;	
			  display: flex;
			  align-items: center;
	 }
	 .title .line{
		width: 8rpx;
		height: 35rpx;
		background-color: #F9A02A;
		border-radius: 40rpx;
		margin-right: 8rpx;
		margin-top:4rpx;
	 }
	 textarea{
		 width:100%;
		 padding:20rpx;
		 border:1rpx solid #f6f6f6;
		 border-radius: 7rpx;
		 margin: 20rpx 0 40rpx;
		 box-sizing: border-box;
		 font-size: 28rpx;
		 
	 }
	 .imgs{
		 display: flex;
		 justify-content: center;
		 width: 200rpx;
		 height: 200rpx;
		 border-radius: 7rpx;
		 line-height: 250rpx;
		 text-align: center;
		 align-items: center;
		 background-color: #f6f6f6;
		 margin-left: 10px;
	 }
	 .imgs image{
		 width: 80%;
		 height: 80%;
	 }
	 .head{
		 font-size: 32rpx;
		 color: #ccc;
	 }

</style>
